from django.contrib import admin

# Register your models here.

from .models import Grades, Students


#注册
#创建班级要求加入的学生信息
class StudentsInfo(admin.TabularInline):
    model = Students
    extra = 1


@admin.register(Grades)
class GradesAdmin(admin.ModelAdmin):
    '''列表页属性'''
    #创建班级自动要求添加两个学生
    inlines = [StudentsInfo]
    # 页签需要显示的字段
    list_display = ['pk', 'gname', 'gdate',
                    'ggirlnum', 'gboynum', 'isDelete']
    # 过滤字段
    list_filter = ['gname']
    # 搜索字段
    search_fields = ['gname']
    # 分页
    list_per_page = 5

    # 添加修改页属性  fields与fieldsets不能同时使用
    # 修改属性的先后顺序
    fields = ['gname', 'gdate',
              'ggirlnum', 'gboynum', 'isDelete']
    # 给属性分组
    # fieldsets = [
    #     ("num", {"fields": ['ggirlnum','gboynum']}),
    #     ("base", {"fields": ['gname', 'gdate', 'isDelete']}),
    # ]


# admin.site.register(Grades, GradesAdmin)


# 装饰器  相当于admin.site.register(Students, StudentsAdmin)
@admin.register(Students)
class StudentsAdmin(admin.ModelAdmin):
    list_display = ['pk', 'sname', 'ssex', 'sage',
                    'scontend', 'sgrade', 'isDelete']
    list_per_page = 5



